-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: migrate block definitions to Config API #42
base: develop
Are you sure you want to change the base?
Conversation
@ayushnirwal @justlevine What kind of validation should we add here: snapwp/packages/core/src/config/snapwp-config-manager.ts Lines 200 to 203 in be538ae
|
@justlevine Do we want to enforce lazy loading for the custom block implementations, or do we leave it up to the user to use On a side note, I haven't been able to verify if using |
This is blocked because we cannot import .tsx block definition files into snapwp.config.mjs. cc: @BhumikP |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested the changes, LGTM
@Swanand01 I have updated the issue with the additional tasks discussed. |
export default function EditorBlocksRenderer( { | ||
editorBlocks, | ||
blockDefinitions, | ||
}: EditorBlocksRendererProps ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pros vs cons about keeping this prop, and then having a hierarchy of props?.blockDefinitions || getConfig()?.blockDefinitions || defaultBlockDefinitions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you please tell me a case where the user would want to overwrite the block definitions passed from the config file by passing them as props to EditorBlocksRenderer
?
I can't think of any pros of doing this at the moment.
Also, we are doing something similar to props?.blockDefinitions || defaultBlockDefinitions
here:
snapwp/packages/blocks/src/block-manager/index.tsx
Lines 47 to 70 in 806792d
public static attachRendererToTreeNode = ( node: BlockTreeNode ): void => { | |
const customBlockDefinition = | |
BlockManager.blockDefinitions[ node.type ]; | |
const defaultBlockDefinition = defaultBlockDefinitions[ node.type ]; | |
if ( customBlockDefinition === null ) { | |
// If explicitly set to null in custom definitions, use default renderer | |
node.renderer = BlockManager.blockDefinitions.default || Default; | |
} else if ( customBlockDefinition ) { | |
// If custom definition exists, use it | |
node.renderer = customBlockDefinition; | |
} else if ( defaultBlockDefinition ) { | |
// If no custom definition but default definition exists, use default | |
node.renderer = defaultBlockDefinition; | |
} else { | |
// If no definition found anywhere, use default renderer and prune children | |
node.renderer = BlockManager.blockDefinitions.default || Default; | |
node.children = null; | |
} | |
if ( node.children ) { | |
node.children.map( this.attachRendererToTreeNode ); | |
} | |
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
- Should this PR include tests before merging? Why (not)?
It definitely requires an update our config-api.md
, and overloading-wp-blocks.md
, and a changeset (minor
as is if we're removing the prop, patch
if we're keeping it - changesets doesnt understand SemVer at <1.0.0)
getConfig
What
This PR moves the custom block definitions to the
snapwp.config.ts
file.Instead of passing them as props to the
EditorBlockRenderer
, they are now imported fromgetConfig
Why
Since block definitions are overloadable/configurable, they should be put in the
snapwp.config.ts
file.Related Issue(s):
https://github.com/orgs/rtCamp/projects/141/views/14?pane=issue&itemId=96524753&issue=rtCamp%7Cheadless%7C396
How
The
blockDefinitions
property is added to theSnapWPConfig
interface andSnapWPConfigManager.snapWPConfigSchema
Testing Instructions
core-quote.tsx
inexamples/nextjs/starter/src/app
.snapwp.config.ts
, add:Screenshots
Additional Info
Checklist